package cn.javase.concurrent._并发编程._03_Java线程._线程常用API;

import static java.lang.Thread.sleep;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class _join {

    static int r = 0;

    public static void main(String[] args) throws InterruptedException {
        test1();
    }

    private static void test1() throws InterruptedException {
        log.debug("开始");
        Thread t1 = new Thread(() -> {
            log.debug("开始");
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.debug("结束");
            r = 10;
        });
        t1.start();
        t1.join(); // 等待完成，可以选择等待时间，不选则一直等待
        log.debug("结果为:{}", r);
        log.debug("结束");
    }

}
